package com.example.g32.login

import com.example.base.http.ApiServer
import com.example.base.mvi.BaseViewModel
import com.example.base.room.UserDao
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

@HiltViewModel
class LoginViewModel @Inject constructor(val apiServer: ApiServer, val userDao: UserDao): BaseViewModel<LoginIntent>() {
    override fun handlerIntent(it: LoginIntent) {
        when(it){
            is LoginIntent.login->{
                httpRequest(apiServer.login(it.pass, it.name))
            }

            is LoginIntent.loginRoom->{
                roomRequest(flow { emit(userDao.login(it.uanme, it.pass)) })
            }
            else->{}
        }
    }
}